package io.wdb.modules.activity.wxapp.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.wdb.common.utils.UUIDGenerator;


import io.wdb.modules.activity.wxapp.dao.HdReadActivityDao;
import io.wdb.modules.activity.wxapp.entity.HdReadActivityEntity;
import io.wdb.modules.activity.wxapp.service.HdReadActivityService;



@Service("hdReadActivityService")
public class HdReadActivityServiceImpl implements HdReadActivityService {
	private static Logger logger = LoggerFactory.getLogger(HdReadActivityServiceImpl.class);
	@Autowired
	private HdReadActivityDao hdReadActivityDao;
	
	@Override
	public HdReadActivityEntity queryObject(String id){
		return hdReadActivityDao.queryObject(id);
	}
	
	@Override
	public List<HdReadActivityEntity> queryList(Map<String, Object> map){
		return hdReadActivityDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return hdReadActivityDao.queryTotal(map);
	}
	
	@Override
	public void save(HdReadActivityEntity hdReadActivity){
		//查询hdReadActivity用户是存在
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("unionid", hdReadActivity.getUnionid());
		map.put("wxGroupId", hdReadActivity.getWxGroupId());
		List<HdReadActivityEntity> entities = hdReadActivityDao.queryList(map);
		if(ObjectUtils.isEmpty(entities)) {//不存在再插入
			hdReadActivity.setId(UUIDGenerator.getUUID());
			hdReadActivityDao.save(hdReadActivity);
			logger.info("save HdReadActivityEntity groupId[{}]，unionid[{}],userId[{}]",hdReadActivity.getWxGroupId(),hdReadActivity.getUnionid(),hdReadActivity.getUserId());
		}else {
			//TODO 存在
		}
	}
	
	@Override
	public void update(HdReadActivityEntity hdReadActivity){
		hdReadActivityDao.update(hdReadActivity);
	}
	
	@Override
	public void delete(String id){
		hdReadActivityDao.delete(id);
	}
	
	@Override
	public void deleteBatch(String[] ids){
		hdReadActivityDao.deleteBatch(ids);
	}
	
}
